package ift585.test;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class Serveur {

	private static final int LISTENING_PORT = 65500;
	private static final int BUFFER_LENTGH = 1024;
	private static final byte dataBuffer[] = new byte[BUFFER_LENTGH];
	private DatagramSocket serverSocket = null;
	
	public Serveur() throws SocketException{
		serverSocket = new DatagramSocket(LISTENING_PORT);
	}
	
	public void execute() throws IOException{
		
		DatagramPacket receivedMessage = new DatagramPacket(dataBuffer, dataBuffer.length);
		serverSocket.receive(receivedMessage);

		System.out.println(new String(receivedMessage.getData()));
	}
	
	public static void main(String[] args) {
		try {
			Serveur oneServer = new Serveur();
			oneServer.execute();
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
	
//	public void ecouteLigne(InputStream input) throws IOException{
//		boolean doitEcouter = true;
//		char lettre;
//		char charFinChaine = 0;
//		
//		while (doitEcouter){
//			try{
//				while(input.available() > 0){
//					lettre = (char) input.read();
//					if (lettre == charFinChaine){
//						doitEcouter = false;
//						// Terminer le thread
//						// Fermer Le port (Garbage collector)
//						break;
//					}
//						
//					System.out.println(lettre);
//				}
//			} 
//			catch (Exception e) {
//				System.out.println(e.getMessage());
//			}
//			if (doitEcouter){
//				//go iddle
//			}
//		}
//	}
}
